var OnlineStoreErrorsModule = {
form: null,
errors: {},
after_close: function () {
},
show: function (errors, form, after_close) {
if (typeof after_close === "function") {
this.after_close = after_close;
}
if (typeof form === "undefined") {
form = null;
}
this.form = form;
this.errors = errors;
if (form != null) {
form.find("input, select, textarea").removeClass("is-invalid");
}
$(".errors-modal .multiple-errors").html("");
if (form != null) {
form.find(".is-invalid").removeClass("is-invalid");
}
$.each(errors, function (key, value) {
$(".errors-modal .multiple-errors").append("
" + value + "");
if (form != null) {
form.find("input[name=" + key + "], select[name=" + key + "], textarea[name=" + key + "], .edit-field[field=" + key + "] .rich_search-container--bootstrap .rich_search-selection").addClass("is-invalid");
}
});
$('.errors-modal').modal('show');
},
show_500_error: function (form, after_close) {
var errors = {
message: _t('api_500_error')
}
this.show(errors, form, after_close);
},
show_connection_error: function (form, after_close) {
var errors = {
message: _t('connection_error')
}
this.show(errors, form, after_close);
},
hide: function () {
$('.errors-modal').modal('hide');
},
on_hide: function () {
this.scroll_to_element();
if (typeof this.after_close === "function") {
this.after_close();
this.after_close = function () {
};
}
},
scroll_to_element: function () {
if (this.form != null) {
this.form.find("[name=" + Object.keys(this.errors)[0] + "]").focus();
}
},
};
$('.errors-modal').on('hidden.bs.modal', function () {
OnlineStoreErrorsModule.on_hide();
});